'use strict';
import React, { Component } from 'react';
import {
  View,
  StyleSheet,
  Text,
  TouchableOpacity,
} from 'react-native';
import NavBar from '../components/NavigatorBar';
import * as defaultStyles from '../constants/DefaultStyles';
import { Actions } from 'react-native-router-flux';
import JPushModule from 'jpush-react-native';

export default class MySettingContainer extends Component {
  constructor(props) {
    super(props);
    this.state = {
      speech: speech,
    }
  }
  _leftClick() {
    Actions.pop();
  }
  _logout() {
    storage.remove({
      key: 'merid'
    });
    JPushModule.setAlias('',
      (success)=> {
        console.log("成功")
      }, (fail) => {
        console.log("失败")
      });
    Actions.login({type: 'reset'});
  }
  _speech() {
    storage.save({
      key: 'merid',
      rawData: {
        uname: uname,
        merid: merid,
        speech: !speech,
      },
      expires: null
    }).then(() => {
      speech = !speech;
      this.setState({speech: speech});
    });
  }
  render() {
    return(
      <View style={styles.container}>
        <NavBar leftImage="angle-left" navBarColor={defaultStyles.LIGHTBLUE}
                leftClick={this._leftClick.bind(this)} title="设置"/>
        {/*<View style={{height: 60, width: defaultStyles.SCREENWIDTH, justifyContent: 'center',*/}
        {/*backgroundColor: defaultStyles.WHITEOFBACKGROUND, alignItems: 'center'}}>*/}
          {/*<TouchableOpacity onPress={() => this._speech()} style={{height: 60, justifyContent: 'center'}}>*/}
            {/*<Text style={{color: defaultStyles.LIGHTBLUE, fontSize: 16}}>{this.state.speech ? "关闭语音播放" : "开启语音播放"}</Text>*/}
          {/*</TouchableOpacity>*/}
        {/*</View>*/}
        <View style={{height: 60, width: defaultStyles.SCREENWIDTH, justifyContent: 'center',
        backgroundColor: defaultStyles.WHITEOFBACKGROUND, alignItems: 'center'}}>
          <TouchableOpacity onPress={() => this._logout()} style={{height: 60, justifyContent: 'center'}}>
            <Text style={{color: defaultStyles.LIGHTBLUE, fontSize: 16}}>退出登录</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  }
});